package com.easonji.common.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * @ClassName: JsonUtils
 * @Description: Json工具类
 * @Author: LiuJun
 * @date: 2018/07/24 16:10
 * @Version: 1.0
 * @Copyright: Copyright (c) 2018 - 2019
 */
public class JsonUtils {

    /**
     * 对象转JSONObject
     */
    public static JSONObject parseObject(Object object) {
        if (StringUtils.isEmpty(object)) {
            return new JSONObject();
        }
        return JSONObject.parseObject(JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss",
                SerializerFeature.WriteDateUseDateFormat));
    }

    /**
     * 对象转JSONArray
     */
    public static JSONArray parseArray(Object object) {
        if (StringUtils.isEmpty(object)) {
            return new JSONArray();
        }
        return JSONObject.parseArray(JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss",
                SerializerFeature.WriteDateUseDateFormat));
    }
}
